﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace EntityFrameworks.Data.Core
{
    /// <summary>
    /// 结果集缓存
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public sealed class QueryableCache<T> where T : class
    {

        #region Fields
        // Lock对象，线程安全所用
        private static object syncRoot = new Object();
        #endregion

        #region Contructors

        #endregion

        #region Properties
        /// <summary>
        /// 缓存数据
        /// </summary>
        public static List<T> Instance { get; private set; }
        #endregion

        #region Methods
        /// <summary>
        /// 重新加载数据结果集
        /// </summary>
        /// <returns></returns>
        public static List<T> Init(IQueryable<T> data)
        {
            lock (syncRoot)
            {
                if (data == null)
                    throw new ArgumentException("数据源不能不空,请先对DataQueryable属性赋值");
                Instance = data.ToList();
            }
            return Instance;
        }
        #endregion

        #region Events

        #endregion

    }
}
